package com.dzt.cloudreader.utils;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;

import com.dzt.cloudreader.R;

import java.util.Random;

/**
 * Created by M02323 on 2017/12/26.
 */

public class JCommonKit {

	/**
	 * 随机颜色
	 */
	public static int randomColor() {
		Random random = new Random();
		int red = random.nextInt(150) + 50;//50-199
		int green = random.nextInt(150) + 50;//50-199
		int blue = random.nextInt(150) + 50;//50-199
		return Color.rgb(red, green, blue);
	}

	public static void share(Context context, String extraText) {
		Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.action_share));
		intent.putExtra(Intent.EXTRA_TEXT, extraText);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(
				Intent.createChooser(intent, context.getString(R.string.action_share)));
	}

	/**
	 * 实现文本复制功能
	 *
	 * @param content 复制的文本
	 */
	public static void copy(Context context, String content) {
		context = context.getApplicationContext();
		// 得到剪贴板管理器
		ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
		cmb.setText(content.trim());
	}

	/**
	 * 使用浏览器打开链接
	 */
	public static void openLink(Context context, String content) {
		context = context.getApplicationContext();
		Uri issuesUrl = Uri.parse(content);
		Intent intent = new Intent(Intent.ACTION_VIEW, issuesUrl);
		context.startActivity(intent);
	}
}
